﻿@using ECGadmin.WebUI.Models
@using ECGadmin.WebUI.CustomHelpers
@model IEnumerable<ECGadmin.Common.ProviderListDto>

@{
    ViewBag.Title = "SearchProvider";
    Layout = "~/Views/Shared/_layout.cshtml";
}
<div class="toolBox">
    @Html.ToolBox(new List<object> { new Add { ClassCss = "Add", ActionName = "/Admin/Provider/Add" } })
</div>
<div class="box-search">
    @using(Html.BeginForm("SearchProvider", "Provider"))
    {
        @Html.TextBox("keyword")
        <input type="submit" value="Tìm kiếm" />
    }
</div>
<table class="table-odd table-plist">
    <tr>
        <th style="width: 30px;">STT</th>
        <th style="width: 50px;">Hình ảnh</th>
        <th>Tên</th>
        <th style="width: 50px;">Vị trí</th>
        <th style="width: 30px;">Tab</th>
        <th style="width: 100px;"></th>
    </tr>

    @{
        if (Model.Any())
        {
            foreach (var item in Model)
            {
                <tr>
                    <td align="center">@item.STT</td>
                    <td align="center">
                        <img src="/upload/ProviderImages/@item.ImagePath" width="45" height="45"/>
                    </td>
                    <td>
                        <a href="@Url.Action("Edit", "Provider", new {id = @item.Id})">@item.Name</a>
                    </td>
                    <td>
                        @item.Ordering
                    </td>
                    <td align="center">
                        <input type="checkbox" checked="@item.ShowHome" />
                    </td>
                    <td>
                        <a href="@Url.Action("Edit", "Provider", new {id = @item.Id})">Edit</a> |
                        <a href="javascript:void(0);" onclick="DeleteColor(@item.Id)">Xóa</a>
                    </td>
                </tr>
            }
        }
    }
</table>
<div class="p-paging">
    @Html.PageLinks((PageInfo)ViewBag.PageInfo, i => Url.Action("Index", "Provider", new { page = i }))
</div>
@section scripts
{
    <script type="text/javascript">
        function DeleteColor(id) {
            $.ajax({
                url: '/Provider/DeleteProvider',
                data: { id: id },
                success: function (data) {
                    if (data) {
                        alert('Xóa provider thành công!');
                        window.location = '/Admin/Provider';
                    } else {
                        alert('Xóa provider thất bại!');
                    }
                },
                error: function () {
                    alert('Đã có lỗi xảy ra!');
                }
            });
        }
    </script>
}

